;;; This file is part of guix-bavier.git
;;; Copyright © 2019 Eric Bavier <bavier@member.fsf.org>
;;; License: GPLv3+

(define-module (bavier packages embedded)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system glib-or-gtk)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages bdw-gc)
  #:use-module (gnu packages bison)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages flex)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages popt)
  #:use-module (gnu packages python)
  #:use-module (gnu packages readline)
  #:use-module ((guix licenses) #:prefix license:))

(define-public gputils
  (package
    (name "gputils")
    (version "1.5.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://sourceforge/gputils/gputils/"
                                  version "/gputils-" version ".tar.bz2"))
              (sha256
               (base32
                "1xfvmvb6zyzs5bqycbvmc6hyl2vp2pv22aaq5974vip4rriklhf7"))))
    (build-system gnu-build-system)
    (home-page "https://gputils.sourceforge.io/")
    (synopsis "Utilities for PIC microcontrollers")
    (description "GPUTILS (GNU PIC Utilities) is a collection of tools for the
Microchip PIC microcontrollers.  It includes gpasm, gplink, and gplib.")
    (license license:gpl2+)))

(define-public gpsim
  (package
    (name "gpsim")
    (version "0.31.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://sourceforge/gpsim/gpsim/"
                                  version "/gpsim-" version ".tar.gz"))
              (sha256
               (base32
                "0gwjd6appj8bzh1hg0z0fbpj7m69pw64h7m90clb60jx7azfc3hi"))))
    (build-system glib-or-gtk-build-system)
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (inputs
     `(("glib" ,glib)
       ("gtk+" ,gtk+-2)
       ("popt" ,popt)
       ("readline" ,readline)))
    (arguments
     `(#:configure-flags '("CXXFLAGS=-std=c++11")))
    (home-page "http://gpsim.sourceforge.net/")
    (synopsis "Software emulator for PIC microcontrollers")
    (description "gpsim is a full-featured software simulator for Michrochip
PIC microcontrollers.  gpsim has been designed to be as accurate as possible.
Accuracy includes the entire PIC -- from the core to I/O pins and including
@emph{all} of the internal peripherals.")
    (license (list license:gpl2+ license:lgpl2.1+))))

(define-public treedec
  (let ((commit "aceed466aebd2e9f898172f3a5c3d9f481dfdb63")
        (revision "0"))
    (package
      (name "treedec")
      (version (git-version "0.9.0" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/freetdi/tdlib.git")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "06w32y3jfanb7z58gb5q8psmsn2606px0lx9kq2vhv47ly2v7zv6"))))
      (build-system gnu-build-system)
      (native-inputs
       `(("autoconf" ,autoconf)
         ("automake" ,automake)
         ("libtool" ,libtool)))
      (inputs
       `(("boost" ,boost)))
      (home-page "https://github.com/freetdi/tdlib")
      (synopsis "Library of tree decomposition algorithms")
      (description "Treedec provides tree decomposition algorithms.")
      (license license:gpl3+))))

(define-public sdcc
  (package
    (name "sdcc")
    (version "3.9.0")
    ;; TODO: snippet should remove non-free Microchip Pic device headers and
    ;; linker scripts.  XXX: Does this mean that we also need to disable pic
    ;; support entirely? or just the pic14 and pic16 ports?  Does this also
    ;; mean we don't need gputils?
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://sourceforge/sdcc/sdcc/"
                                  version "/sdcc-src-" version ".tar.bz2"))
              (sha256
               (base32
                "0dn0cy6whcrvbfh9x467jdi8dmzjrvixz2bz63pgxwzpz9rsxv4l"))))
    (build-system gnu-build-system)
    (native-inputs
     `(("flex" ,flex)
       ("bison" ,bison)
       ("perl" ,perl)
       ("python" ,python)
       ("gputils" ,gputils)))
    (inputs
     `(("boost" ,boost)
       ("libgc" ,libgc)
       ("treedec" ,treedec)
       ("zlib" ,zlib)))
    (arguments
     `(#:configure-flags '("CXXFLAGS=-std=c++11" ; For treedec
                           "--disable-non-free"
                           "--enable-libgc")
       #:phases (modify-phases %standard-phases
                  (add-before 'build 'patch-more-makefile-SHELL
                    (lambda _
                      (for-each patch-makefile-SHELL
                                '("main.mk"
                                  "Makefile.common"
                                  "sim/ucsim/main.mk"
                                  "support/sdbinutils/bfd/po/Make-in"))
                      #t)))))
    (home-page "http://sdcc.sourceforge.net/")
    (synopsis "Small Device C Compiler")
    (description "SDCC is a retargettable, optimizing Standard C compiler
suite that targets the Intel MCS51 based microprocessors (8031, 8032, 8051,
8052, etc.), Maxim (formerly Dallas) DS80C390 variants, Freescale (formerly
Motorola) HC08 based (hc08, s08), Zilog Z80 based MCUs (z80, z180, gbz80,
Rabbit 2000/3000, Rabbit 3000A, TLCS-90), Padauk (pdk14, pdk15) and
STMicroelectronics STM8.  It can be retargeted for other microprocessors.")
    (license license:gpl2)))
